﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestSystem.Domain.Abstract;
using TestSystem.Domain.DAL;
using TestSystem.Domain.Entities.Questions;

namespace TestSystem.Domain.Repositories
{
    public class QuestionRepository : IQuestionRepository
    {
        private TestSystemContext dbContext = new TestSystemContext();

        public IQueryable<Question> Questions { get { return dbContext.Questions; }}
        public void AddQuestion(Question question)
        {
            dbContext.Questions.Add(question);
            dbContext.SaveChanges();
        }

        public void RemoveQuestion(Question question)
        {
            dbContext.Questions.Remove(question);
            dbContext.SaveChanges();
        }

        public IQueryable<QuestionAttribute> QuestionAttributes { get { return dbContext.QuestionAttributes; } }
        public IQueryable<QuestionAttributeType> QuestionAttributeTypes { get { return dbContext.QuestionAttributeTypes; } }
        public IQueryable<ChoiceQuestionAnwser> ChoiceQuestionAnwsers { get { return dbContext.ChoiceQuestionAnwsers; } }
        public void AddChoiceQuestionAnwsers(IEnumerable<ChoiceQuestionAnwser> choiceQuestionAnwsers)
        {
            choiceQuestionAnwsers.Select(cq => dbContext.ChoiceQuestionAnwsers.Add(cq));
            dbContext.SaveChanges();
        }
        public void RemoveChoiceQuestionAnwsers(ChoiceQuestionAnwser choiceQuestionAnwser)
        {
            dbContext.ChoiceQuestionAnwsers.Remove(choiceQuestionAnwser);
            dbContext.SaveChanges();
        }

        public IQueryable<OpenQuestionAnwser> OpenQuestionAnwsers { get { return dbContext.OpenQuestionAnwsers; } }
        public void RemoveOpenQuestionAnwsers(OpenQuestionAnwser openQuestionAnwser)
        {
            dbContext.OpenQuestionAnwsers.Remove(openQuestionAnwser);
            dbContext.SaveChanges();
        }

        public IQueryable<ChoiceAnwserType> ChoiceAnwserTypes { get { return dbContext.ChoiceAnwserTypes; } }
        public IQueryable<QuestionType> QuestionTypes { get { return dbContext.QuestionTypes; } }
        public IQueryable<Difficulty> Difficulties { get { return dbContext.Difficulties; } } 
    }
}
